//
//  SYSpecialTVCell.m
//  TermOfSectionB
//
//  Created by 韩震明 on 15/11/27.
//  Copyright © 2015年 韩震明. All rights reserved.
//

#import "SYSpecialTVCell.h"

@implementation SYSpecialTVCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createMyCell];
    }
    return self;
}

- (void)createMyCell
{
    self.picImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.picImageView];
    self.picImageView.layer.cornerRadius = 5;
    self.picImageView.layer.masksToBounds = YES;
    
    self.backOfTitle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"backOfTitle"]];
    [self.picImageView addSubview:self.backOfTitle];
    self.backOfTitle.alpha = 0.2;
    
    self.titleLabel = [[UILabel alloc] init];
    [self.picImageView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:18.0];
    self.titleLabel.textColor = [UIColor whiteColor];
    
    
    
    self.likeImageView = [[UIImageView alloc] init];
    [self.picImageView addSubview:self.likeImageView];
    self.likeImageView.layer.cornerRadius = 5;
    self.likeImageView.layer.masksToBounds = YES;
    self.likeImageView.alpha = 0.9;
    
    self.likeLabel = [[UILabel alloc] init];
    [self.likeImageView addSubview:self.likeLabel];
    self.likeLabel.font = [UIFont systemFontOfSize:8.0];
    self.likeLabel.textAlignment = NSTextAlignmentCenter;
    self.likeLabel.textColor = [UIColor whiteColor];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.picImageView makeConstraints:^(MASConstraintMaker *make) {
        Left(self.contentView, 10);
        Right(self.contentView, - 10);
        Top(self.contentView, 5);
        Bottom(self.contentView, - 5);
    }];
    
    [self.backOfTitle makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.and.bottom.equalTo(self.picImageView);
        Top(self.contentView, 115);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        Left(self.picImageView, 10);
        Top(self.backOfTitle, 0);
        Right(self.picImageView, 0);
        Bottom(self.picImageView, 0);
    }];
    
    [self.likeImageView makeConstraints:^(MASConstraintMaker *make) {
        Top(self.picImageView, 2);
        Right(self.picImageView, - 5);
        WIDTHToNum(30);
        HEIGHTToNum(30);
    }];
    
    [self.likeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.and.bottom.equalTo(self.likeImageView);
        make.top.equalTo(self.likeImageView.centerY);
    }];
    
    [self reloadData];
}

- (void)reloadData
{
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:[self.topicModel pic]] placeholderImage:[UIImage imageNamed:@"back.gif"]];
    self.titleLabel.text = [self.topicModel title];
    self.likeImageView.image = [UIImage imageNamed:@"like.png"];
    self.likeLabel.text = [self.topicModel likes];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
